<template>
    <div class="body">
       <img src="../assets/live-logo.gif" alt="">
    </div>
</template>
<script>
import {wechatLogin,GetConfig} from '../ajax';
export default {
    name: 'WxAuth',
    async created(){
      let query = window.location.search.split('=');
      const code = query[1].split('&')[0];
      const admin_id = query[2].split('-')[0];
      const state = query[2].split('-')[1];
      if (code) {
          this.$store.commit('admin_id',admin_id)
          const data = {
              code,
              admin_id,
              state:state !== 'undefined'?state:''
          }
            let redirectUrl = sessionStorage.getItem('wxRedirectUrl');
          wechatLogin(data).then(res=>{
            const params = {
              admin_id
            }
            GetConfig(params).then(response=>{
              this.$store.commit('get_config',response);
            })
            this.$store.commit('wxUserInfo',res);
              // console.log(redirectUrl);
            window.location.href = redirectUrl;
          })
      } else {
        this.$router.replace('/')
      }
    },
  }
</script>
<style scoped lang="scss">
    .body{
        height: calc(100vh - 4rem);
        display: flex;
        justify-content: center;
        align-items: center;
        img{
            width: 8rem;
            height: 8rem;
        }
    }
    
</style>